#include <string>
#include <SDL_mixer.h>

#include "Audio.hpp"

namespace fge
{

SoundEffect::~SoundEffect()
{
	if(mixChunk != NULL)
		Mix_FreeChunk(mixChunk);
}

SoundEffect* SoundEffect::FromFile(const std::string &fileName)
{
	SoundEffect *soundEffect = new SoundEffect();
	soundEffect->mixChunk = Mix_LoadWAV(fileName.c_str());

	if(soundEffect->mixChunk == NULL)
	{
		delete soundEffect;
		return NULL;
	}

	return soundEffect;
}

Song::~Song()
{
	if(mixMusic != NULL)
		Mix_FreeMusic(mixMusic);
}

Song* Song::FromFile(const std::string &fileName)
{
	Song *song = new Song();
	song->mixMusic = Mix_LoadMUS(fileName.c_str());

	if(song->mixMusic == NULL)
	{
		delete song;
		return NULL;
	}

	return song;
}

}

